import qs from 'qs';
import { requestGet, requestPost, requestPut } from '../utils/requestApi';

import {
  getList,
  getDetail,
  getNewsInfo,
  addItem,
  sendPhoneVerificationCode,
  getWechatConfig,
  postMethod,
} from './service';
import { get } from 'react-hook-form';

export async function getProductList(payload) {
  return getList('web/exhibitPage', payload);
}
// export async function getSearchProduct(paylaod) {
//     return requestGet('product', payload)
// }
export async function getProductDetail(payload) {
  console.log(payload);
  return getDetail('web/exhibit', payload);
}
export async function getExProducts(payload) {
  // const params = qs.stringify(
  //   // { sort: ['orderNumber,desc', 'createTime,desc'] },
  //   { arrayFormat: 'repeat' },
  // );
  return getList(`web/exhibitPage?exhibitorId=${payload.exhibitorId}`); //&enabled=true&${params}
}
export async function getExhibitorList(payload) {
  return getList('exhibitors', payload);
}
export async function getExhibitorDetail(payload) {
  return getDetail(`web/exhibitor`, payload);
}
export async function getNews(payload) {
  return getList(`web/articlePage`, payload);
}

export async function getNewsDetail(payload) {
  return getNewsInfo(`web/article`, payload);
}

export async function getVideoList(payload) {
  return getList('web/articlePage', { ...payload, type: 'video' });
}
export async function postSmsCode(paylaod) {
  return sendPhoneVerificationCode(paylaod);
}
export async function postLogin(payload) {
  return addItem(`web/login/byAudience`, payload);
}
export async function postExhibitorLogin(payload) {
  return addItem(`web/login/byExhibitor`, payload);
}
export async function getUserSelf(payload) {
  return;
}
export async function postLikeProduct(payload) {
  return addItem('web/operationAll', payload);
}
export async function postLikeExhibitor(payload) {
  return addItem('web/operationAll', payload);
}
export async function postLikeNews(payload) {
  return addItem('web/operationAll', payload);
}

export async function postWantbuy(payload) {
  return addItem('web/enquiry', payload);
}

export async function getLikeProductList(payload) {
  return getList('my/operationRecordPage', payload);
}
export async function getLikeNewsList(payload) {
  return getList('my/operationRecordPage', payload);
}
export async function getLikeExhibitorList(payload) {
  return getList(`my/operationRecordPage`, payload);
}
export async function postReceipt(payload) {
  return requestPost('receipt', payload);
}

export async function getWantbuyList(payload) {
  return getList(`my/enquiryPage`, payload);
}
export async function getWantbuyDetail(payload) {
  return getDetail(`web/enquiry`, payload);
}
export async function getExhibitor2021(payload) {
  return requestGet('exhibitor2021', payload);
}
export async function getExhibitCategoryList(payload) {
  return getList('web/category', payload);
}
export async function getArticleCategoryList(payload) {
  return getList('web/article-category', payload);
}
export async function getArticleList(payload) {
  return getList('article', payload);
}
export async function getBannerList(payload) {
  return getList('web/getAdvertisement', payload);
}

export async function getMeetingList(payload) {
  return getList('web/conferencePage', { ...payload, arrayFormat: 'repeat' });
}

export async function getMeetingDetail(payload) {
  return getList(`web/meeting/${payload.id}`);
}

export async function getVenues(payload) {
  return getList('web/venue', payload);
}

export async function fetchWechatConfig(payload) {
  return getWechatConfig(payload);
}

export async function fetchBusinessMatchList(payload) {
  return getList('business-opportunity', payload);
}

export async function fetchBusinessMatchDetail(payload) {
  return getList(`business-opportunity/${payload.id}`);
}

export async function addBusinessMatchApply(payload) {
  return postMethod('business-opportunity-meet-apply', payload);
}

export async function checkEmailIsExist(email) {
  return postMethod(`web/login/emailIsExist?email=${email}`);
}
